function bind_email() {
    $("#captcha-btn").click(function (e) {
        // 代表当前按钮的jquery对象
        let $this = $(this)
        // console.log("success")
        e.preventDefault();

        let email = $("#email").val()
        // 邮箱匹配
        let flag = /^\w+(\/\w+)*@\w+(\.\w+)+$/;
        if (email === "" || !flag.test(email)) {
            alert("请输入正确邮箱格式后再重新申请验证码发送")
        } else {
            // console.log(email)
            $.ajax({
                url: "/register/captcha?email=" + email,
                methods: "GET",
                success: function (res) {
                    console.log(res)
                    let code = res['code']
                    if (code === 200) {
                        let countdown = 60;
                        // 取消按钮的点击事件
                        $this.off("click")
                        let timer = setInterval(function () {
                            $this.text("(" + countdown + ")");
                            countdown -= 1;
                            if (countdown <= 0) {
                                // 清除定时器
                                clearInterval(timer)
                                $this.text("获取验证码")

                                bind_email()
                            }
                        }, 1000);
                    } else {
                        alert(res['message'])
                    }
                },
                error:function (err){
                    console.log(err)
                }
            })
        }
    });
}

$(function () {
    bind_email();
});